package com.sskj.gocoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.util.MD5Util;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.http.JsonCallBack;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.BindEmailActivity;

/**
 * Created by Administrator on 2018/4/2 0002.
 */

public class BindEmailPresenter extends BasePresenter<BindEmailActivity> {

    public void sendEmai(String email) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL)
                .params("email", email)
                .params("is_app", "1")
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.sendCheckCodeSuccess();
                        } else {
                            mView.sendCheckCodeFail();
                        }
                        ToastUtil.showShort(httpListData.getMsg());
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                        mView.sendCheckCodeFail();
                    }
                });
        ;
    }

    public void requestBindEmail(String code, String newEmail,String tpwd) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_EMAIL)
                .params("code", code)
                .params("email", newEmail)
                .params("tpwd", MD5Util.getMd5Value(tpwd))
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            ToastUtil.showShort(httpListData.getMsg());
                            mView.onResponseSuccess();
                        } else {
                            ToastUtil.showShort(httpListData.getMsg());
                        }
                    }
                });
    }

    //验证谷歌验证码
    public void requestGoogleCheck(String googleCode,String code,String email,String tpwd) {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.GOOGLE_LOGIN)
                .params("dyGoodleCommand", googleCode)
                .execute(new com.sskj.gocoin.m.http.JsonCallBack<HttpData<String>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<String>> response) {
                        HttpData<String> body = response.body();
                        if (body.getCode() == 200) {
                            mView.googleCheckSuccess(code, email, tpwd);
                        } else {
                            com.sskj.gocoin.utils.ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }
}
